<%@ page language="java" isELIgnored="false"%>
<%@include file="../common/taglib.jsp"%>

<div id="Conteudo">
	<html:form action="variavel">
		<html:hidden property="codigo"></html:hidden>
		<html:hidden property="method"></html:hidden>
		<html:hidden property="state"></html:hidden>
		<h1><bean:message key="contato.label.title"/>:<span><bean:message key="subtitulo.label.cadastro"/></span> </h1>
		<div class="campo">
			<label>
				<bean:message key="variavel.label.nova"/><span>*</span>
			</label>
			<html:checkbox property="novaVariavel" value="S" onclick="novoCadastroVariavel();"></html:checkbox>
		</div>
		<br clear="all"/>
		<div class="campo" style="display: none" id="divNovaVariavel">
			<label>
				<bean:message key="variavel.label.descricao"/><span>*</span>
			</label> 
			<html:text property="descricao" style="width:500px;" maxlength="100"></html:text>
		</div>
		<div class="campo" id="divSelect">
			<label>
				<bean:message key="variavel.label.descricao"/><span>*</span>
			</label> 
			<html:select property="codigoAux">
				<trex:options source="br.com.ia.business.VariavelBusiness.retrieveAll()" property="codigo" labelProperty="descricao"/>
			</html:select>
		</div>
		<br clear="all"/>
		<div class="campo">
			<label>
				<bean:message key="valor.label.descricao"/><span>*</span>
			</label>
			<html:text property="valor.descricao" style="width:500px;" maxlength="100"></html:text>
		</div>					
		
	</html:form>
	
	<%-- <facility-tags:error/>	--%>
	
</div>
<script>
	
	function cancelar(){
		
		document.VariavelForm.method.value = 'prepareSearch';
		document.VariavelForm.submit();		
	}
	
	function salvar(){
		
		var estado = document.VariavelForm.state.value;
		
		if (estado == 'insert'){
			document.VariavelForm.method.value = 'insert';
		}
		else if (estado == 'update'){
			document.VariavelForm.method.value = 'update';
		}
				
		document.VariavelForm.submit();		
	}

	function novoCadastroVariavel(){
		var check = document.VariavelForm.novaVariavel.checked;
		var oDivNovaVariavel = document.getElementById('divNovaVariavel');
		var oDivSelect = document.getElementById('divSelect');
		
		if(check){
			oDivNovaVariavel.style.display = "block";
			oDivSelect.style.display = "none";
		}else{
			oDivNovaVariavel.style.display = "none";
			oDivSelect.style.display = "block";
		}
	}
	
</script>